package com.llbnk.srb.sms.util;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * @author shkstart
 * @create 2022-04-13 11:12
 */
@Data
@Component //spring程序就可以自动创建整个类的对象
// 根据ConfigurationProperties(prefix = "aliyun.sms")的一个参数，自动组装里面的值
@ConfigurationProperties(prefix = "aliyun.sms")//读取配置文件注解读取的是aliyun.sms这部分
public class SmsProperties implements InitializingBean {

    /**
     * region-id: cn-hangzhou
     *     key-id: LTAI4G5Svnb2TWBMuKnNT6jY
     *     key-secret: N7v6R4v3EJ1SGDZlsqtqo8QyVVMmtQ
     *     template-code: SMS_96695065
     *     sign-name: 谷粒
     */

    //对应application中的格式可以识别驼峰和-格式
    private String regionId;
    private String keyId;
    private String keySecret;
    private String templateCode;
    private String signName;

    public static String REGION_Id;
    public static String KEY_ID;
    public static String KEY_SECRET;
    public static String TEMPLATE_CODE;
    public static String SIGN_NAME;

    /**
     * InitializingBean是spring提供的接口
     * 这个接口是afterPropertiesSet就是上面这个regionId参数被spring设置完成之后（Component注解负责）
     * 调用这个
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        REGION_Id = regionId;
        KEY_ID = keyId;
        KEY_SECRET = keySecret;
        TEMPLATE_CODE = templateCode;
        SIGN_NAME = signName;
    }
}
